package bat.ke.qq.com;

import bat.ke.qq.com.aop.AopMethodInterceptor;
import org.aopalliance.aop.Advice;
import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.aop.support.NameMatchMethodPointcutAdvisor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * 源码学院-Fox
 * 只为培养BAT程序员而生
 * http://bat.ke.qq.com
 * 往期视频加群:516212256 暗号:6
 */
@Configuration
@ComponentScan("bat.ke.qq.com")
@EnableAspectJAutoProxy(proxyTargetClass=false)
public class AppConfig {


    @Bean
    public Advice aopMethodInterceptor(){
        return new AopMethodInterceptor();
    }


//	@Bean
//	public BeanNameAutoProxyCreator beanNameAutoProxyCreator(){
//        //使用BeanNameAutoProxyCreator来创建代理
//		BeanNameAutoProxyCreator beanNameAutoProxyCreator=new BeanNameAutoProxyCreator();
//		//设置要创建代理的 beanNames  类
//		beanNameAutoProxyCreator.setBeanNames("*Dao","*Service");
//		//设置拦截链名字(有先后顺序)   通知
//		beanNameAutoProxyCreator.setInterceptorNames("aopMethodInterceptor");
//		return beanNameAutoProxyCreator;
//	}


//    @Bean
//    public NameMatchMethodPointcutAdvisor nameMatchMethodPointcutAdvisor(){
//        NameMatchMethodPointcutAdvisor nameMatchMethodPointcutAdvisor=
//                new NameMatchMethodPointcutAdvisor();
//        // 方法级别
//        nameMatchMethodPointcutAdvisor.setMappedNames("query*","find*");
//        nameMatchMethodPointcutAdvisor.setAdvice(aopMethodInterceptor());
//        return nameMatchMethodPointcutAdvisor;
//    }
////
//    @Bean
//    public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator(){
//        return new DefaultAdvisorAutoProxyCreator();
 //   }


}
